<?php echo $header;?>
<div id="content">
  <div class="box">
   <div class="heading">
      <h1><img src="view/image/information.png" alt="" /> <?php echo $heading_title; ?></h1>
      <div class="buttons"><a onclick="$('#form').submit();" class="button"><?php echo $button_save; ?></a><a href="<?php echo $cancel; ?>" class="button"><?php echo $button_cancel; ?></a></div>
    </div>
     <div class="content">
      <form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form">
		<table class="form">
         <tr>
          	<td><span class="required">*</span> <?php echo "accessToken:"; ?></td>
            <td ><select name="common_id">
            <?php foreach ($commons as $common){?>
            	<?php if($common_id==$common["common_id"]){?>
            	<option selected="selected" value="<?php echo $common["common_id"];?>"><?php echo $common["common_name"];?></option>
            	<?php }else{ ?>
            	<option  value="<?php echo $common["common_id"];?>"><?php echo $common["common_name"];?></option>
            	<?php }?>
            <?php }?>	
		            </select>
					</td>
			      </tr>
  			 	 <tr>
		          	<td><span class="required">*</span> <?php echo "名称:"; ?></td>
            <td ><input   id="menu_name" name="menu_name" value="<?php echo $menu_name;?>"></textarea>
			</td>
	      </tr>
        </table>


        <table id="route" class="list">
          <thead>
            <tr>
              <td class="left" style="width:140px;"><?php echo "子菜单"; ?></td>
              <td class="left" style="width:100px;"><?php echo "类型"; ?></td>
              <td class="left">名称</td>
              <td class="left">url/view</td>
              <td class="left span1" ><?php echo "排序"; ?></td>
              <td class="span2"></td>
            </tr>
          </thead> 
          <?php $route_row = 0; ?>
          <?php $sub_route_row = 0; ?>
          <?php foreach ($menu_routes as $menu) { ?>
           <?php if(isset($menu['type'])) { ?>
            
         	<tbody id="route-row<?php echo $route_row; ?>">
        		<input name="menu_route[<?php echo $route_row; ?>][row]" value="<?php echo $route_row; ?>" type="hidden" />
				<tr>  <td class="left">  <a onclick="addSubRoute(<?php echo $route_row; ?>);" class="button"><span><?php echo "增加子菜单"; ?></span></a>  </td> 
				 <td class="left">
					<select name="menu_route[<?php echo $route_row; ?>][type]" onchange="$('#route<?php echo $route_row; ?>').load('index.php?route=design/menu/name&token=<?php echo $token; ?>&row=<?php echo $route_row; ?>&type='+this.value);$('#url<?php echo $route_row; ?>').load('index.php?route=design/menu/url&token=<?php echo $token; ?>&row=<?php echo $route_row; ?>&type='+this.value);" >
						   <option value="0">-- 请选择链接类型 --</option>
						   <option value="click" <?php if($menu['type']=='click'){?> selected="selected"  <?php }?>>click</option> 
						   <option value="view" <?php if($menu['type']=='view'){?> selected="selected"  <?php }?>>view</option> 
						   <option value="pic_sysphoto" <?php if($menu['type']=='pic_sysphoto'){?> selected="selected"  <?php }?>>pic_sysphoto</option>
						   <option value="location_select" <?php if($menu['type']=='location_select'){?> selected="selected"  <?php }?>>location_select</option>
					</select>
				 </td>		
				 <td class="left" id="route<?php echo $route_row; ?>">
					<input name="menu_route[<?php echo $route_row; ?>][name]" value="<?php echo $menu['name']; ?>" type="text" />
				
				 </td>
				  <td class="left" id="url<?php echo $route_row; ?>">
					<input name="menu_route[<?php echo $route_row; ?>][url]" value="<?php echo $menu['url']; ?>" type="text" />
				
				 </td>
				 <td class="left span1" >
					 <input name="menu_route[<?php echo $route_row; ?>][sort_order]" value="<?php echo $menu['sort_order']; ?>" type="number" class="input-mini"  size="3"/>
				 </td>
				
				
				<td class="left span2"><a onclick="removeRoute('route-row<?php echo $route_row; ?>');" class="button"><span><?php echo $button_remove; ?></span></a></td>
           	</tr>
        	</tbody>
        	 <?php if(isset($menu['sub'])&&$menu['sub']) { ?>
              <?php foreach ($menu['sub'] as $sub_menu) { ?>
              
		        <tbody id="route-row<?php echo $route_row; ?>_<?php echo $sub_route_row; ?>">
        		
				<tr>  <td class="left"> </td> 
				 <td class="left">
					<select name="menu_route[<?php echo $route_row; ?>][sub][<?php echo $sub_route_row; ?>][type]" onchange="$('#route<?php echo $route_row; ?>_<?php echo $sub_route_row; ?>').load('index.php?route=design/menu/name&token=<?php echo $token; ?>&row=<?php echo $route_row; ?>&sub=<?php echo $sub_route_row; ?>&type='+this.value);$('#route<?php echo $route_row; ?>_<?php echo $sub_route_row; ?>').load('index.php?route=design/menu/url&token=<?php echo $token; ?>&row=<?php echo $route_row; ?>&sub=<?php echo $sub_route_row; ?>&type='+this.value);" >
						   <option value="0">-- 请选择链接类型 --</option>
						   <option value="click" <?php if($sub_menu['type']=='click'){?> selected="selected"  <?php }?>>click</option> 
						   <option value="view" <?php if($sub_menu['type']=='view'){?> selected="selected"  <?php }?>>view</option> 
						   <option value="pic_sysphoto" <?php if($sub_menu['type']=='pic_sysphoto'){?> selected="selected"  <?php }?>>pic_sysphoto</option> 
						   <option value="location_select" <?php if($sub_menu['type']=='location_select'){?> selected="selected"  <?php }?>>location_select</option>
					</select>
				 </td>		
				 <td class="left" id="route<?php echo $route_row; ?>_<?php echo $sub_route_row; ?>">
					<input name="menu_route[<?php echo $route_row; ?>][sub][<?php echo $sub_route_row; ?>][name]" value="<?php echo $sub_menu['name']; ?>" type="text" />
				 </td>
				  <td class="left" id="url<?php echo $route_row; ?>_<?php echo $sub_route_row; ?>">
					<input name="menu_route[<?php echo $route_row; ?>][sub][<?php echo $sub_route_row; ?>][url]" value="<?php echo $sub_menu['url']; ?>" type="text" />
				 </td>
				 <td class="left" >
					<input name="menu_route[<?php echo $route_row; ?>][sub][<?php echo $sub_route_row; ?>][sort_order]" value="<?php echo $sub_menu['sort_order']; ?>" type="number" class="input-mini" size="3"/>
				 </td>
				<td class="left"><a onclick="$('#route-row<?php echo $route_row; ?>_<?php echo $sub_route_row; ?>').remove();" class="button"><span><?php echo $button_remove; ?></span></a></td>
           	</tr>
        	</tbody>
		        	<?php $sub_route_row++; ?>
        	    <?php } ?>
             <?php } ?>
        	<?php $route_row++; ?>
            <?php } ?>
          <?php } ?>
          <tfoot>
            <tr>
              <td colspan="5"></td>
              <td class="left"><a onclick="addRoute();" class="button"><span><?php echo $button_add_link; ?></span></a></td>
            </tr>
          </tfoot>
        </table>
      </form>
      </div>
  </div>
  </div>
<script type="text/javascript"><!--
var route_row = <?php echo $route_row; ?>;
var sub_route_row = <?php echo $sub_route_row; ?>;
function addSubRoute(route_row_para) {
	html  = '<tbody id="route-row' + route_row_para + '_'+sub_route_row+'">';
	html += ' <tr>  <td class="left"> </td> ';
	html += ' <td class="left"><select name="menu_route[' + route_row_para + '][sub][' + sub_route_row + '][type]" ';
	html += '   onchange="$(\'#route' + route_row_para + '_'+sub_route_row+'\').load(\'index.php?route=design/menu/name&token=<?php echo $token; ?>&row=' + route_row_para + '&sub=' + sub_route_row + '&type=\' + this.value);$(\'#url' + route_row_para + '_'+sub_route_row+'\').load(\'index.php?route=design/menu/url&token=<?php echo $token; ?>&row=' + route_row_para + '&sub=' + sub_route_row + '&type=\' + this.value);" > ';
	html += '   <option value="0">-- 请选择菜单类型 --</option> ';
	html += '   <option value="click">click</option> ';
	html += '   <option value="view">view</option> ';
	html += '   <option value="pic_sysphoto">pic_sysphoto</option> ';
	html += '   <option value="location_select">location_select</option> ';
	html += '  </select></td>';
	html += ' <td class="left" id="route' + route_row_para + '_'+sub_route_row+'">';
	html += ' </td>';
	html += ' <td class="left" id="url' + route_row_para + '_'+sub_route_row+'">';
	html += ' </td>';
	html += ' <td class="left">';
	html += ' <input name="menu_route[' + route_row_para + '][sub][' + sub_route_row + '][sort_order]" value="' + sub_route_row + '" type="number" class="input-mini" />';
	html += ' </td>';
	
	html += '<td class="left" style="width:120px;"><a onclick="$(\'#route-row' + route_row_para + '_'+sub_route_row+'\').remove();" class="button"><span><?php echo $button_remove; ?></span></a></td>';
	html += '  </tr> ';
	html += '</tbody>';
	$('#route-row' + route_row_para).after(html);
	sub_route_row++;
}

function addRoute() {
	var sub_route_row =0;
	html  = '<tbody id="route-row' + route_row + '">';
	html += ' <input name="menu_route[' + route_row + '][row]" value="' + route_row + '" type="hidden" />';
	html += ' <tr>  <td class="left">  <a onclick="addSubRoute(' + route_row + ');" class="button"><span><?php echo "添加子菜单" ?></span></a>  </td> ';
	html += ' <td class="left"><select name="menu_route[' + route_row + '][type]" ';
	html += '   onchange="$(\'#route' + route_row + '\').load(\'index.php?route=design/menu/name&token=<?php echo $token; ?>&row=' + route_row + '&type=\' + this.value);$(\'#url' + route_row + '\').load(\'index.php?route=design/menu/url&token=<?php echo $token; ?>&row=' + route_row + '&type=\' + this.value);" > ';
	html += '   <option value="0">-- 请选择链接类型 --</option> ';
	html += '   <option value="click">click</option> ';
	html += '   <option value="view">view</option> ';
	html += '  </select></td>';
	html += ' <td class="left" id="route' + route_row + '">';
	html += ' </td>';
	html += ' <td class="left" id="url' + route_row + '">';
	html += ' </td>';
	html += ' <td class="left span1">';
	html += ' <input name="menu_route[' + route_row + '][sort_order]" value="' + route_row + '" type="number" class="input-mini" size="3"/>';
	html += ' </td>';
	html += '<td class="left span2" style="width:120px;"><a onclick="removeRoute(\'route-row' + route_row + '\');" class="button"><span><?php echo $button_remove; ?></span></a></td>';
	html += '  </tr> ';
	html += '</tbody>';
	
	$('#route > tfoot').before(html);
	
	route_row++;
}

function removeRoute(id) {
	$("[id^="+id+"]").remove();
}
//--></script> 

<?php echo $footer;?>
